
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>打印区域控制示例</title>
    <style>
        /* 屏幕样式 */
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            padding: 20px;
        }
        .screen-only {
            background-color: #f0f8ff;
            padding: 15px;
            margin-bottom: 20px;
            border: 1px dashed #4682b4;
        }
        .print-content {
            border: 1px solid #ddd;
            padding: 15px;
            margin-bottom: 20px;
        }
        
        /* 打印样式 */
        @media print {
            .no-print, .screen-only {
                display: none;
            }
            .print-only {
                display: block !important;
                border: none;
                padding: 0;
            }
            @page {
                size: A4;
                margin: 1cm;
            }
            body {
                font-size: 12pt;
                line-height: 1.5;
                color: #000;
            }
        }
    </style>
</head>
<body>
    <div class="screen-only">
        <h2>屏幕专用内容</h2>
        <p>这部分内容只在屏幕显示，打印时会自动隐藏</p>
        <button onclick="window.print()">打印测试</button>
    </div>
    
    <div class="print-content">
        <h2>可打印内容区域</h2>
        <p>这部分内容会正常打印输出</p>
        <div class="no-print">
            <p>这个子区域设置了no-print类，打印时会隐藏</p>
        </div>
    </div>
    
    <div class="print-only" style="display:none;">
        <h3>打印专用内容</h3>
        <p>这部分内容只在打印时显示</p>
        <p>打印日期: 2025年07月31日</p>
    </div>
</body>
</html>
